package mortal.common.preLoadPage
{
	import flash.events.*;
	import flash.net.*;
	
	public class GametipsConfig extends Object
	{
		private var _intervalTime:int = 3;
		private var _tips:Array;
		private static var _instance:GametipsConfig;
		
		public function GametipsConfig()
		{
			if (_instance)
			{
				throw new Error("GametipsConfig 单例！");
			}
		}
		
		public function get intervalTime() : int
		{
			return this._intervalTime;
		}
		
		public function load(urlReq:URLRequest, success:Function) : void
		{
			var onLoaderComplete:Function;
			var onLoaderError:Function;
			onLoaderComplete = function (event:Event) : void
			{
				var xml:XML = null;
				var data:* = new XML((event.target as URLLoader).data);
				_intervalTime = parseInt(data.child("intervalTime").@value);
				_tips = new Array();
				for each (xml in data.child("item"))
				{
					
					_tips.push(String(xml.@value));
				}
				success.call();
			};
			
			onLoaderError = function (event:IOErrorEvent) : void
			{
				trace("Gametips.xml 加载失败！");
			};
			
			var loader:URLLoader = new URLLoader();
			loader.addEventListener(Event.COMPLETE, onLoaderComplete);
			loader.addEventListener(IOErrorEvent.IO_ERROR, onLoaderError);
			loader.load(urlReq);
		}
		
		public function getRandomTip() : String
		{
			var _loc_1:int = 0;
			if (this._tips && this._tips.length >= 1)
			{
				_loc_1 = Math.round((this._tips.length - 1) * Math.random());
				return this._tips[_loc_1] as String;
			}
			return "";
		}
		
		public static function get instance() : GametipsConfig
		{
			if (!_instance)
			{
				_instance = new GametipsConfig;
			}
			return _instance;
		}
	}
}
